home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / tvtool17.zip / TVTOOLS.ZIP / INDATE.CPP < prev    next >
C/C++ Source or Header  |  1993-05-13  |  1KB  |  66 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #define Uses_TStreamable
  4. #define Uses_MsgBox
  5. #define Uses_TInputDate
  6. #include "tvtools.h"
  7. __link( RInputLine )
  8.  
  9.  
  10. #include <string.h>
  11. #include <stdio.h>
  12. #include <values.h>
  13. #include <stdlib.h>
  14. #include <strstream.h>
  15.  
  16. #include "date.h"
  17.  
  18.  
  19. // TInputDate
  20.  
  21. const char * const TInputDate::name = "TInputDate";
  22.  
  23. TInputDate::TInputDate( const TRect& bounds )
  24.            :TInputRegExp( bounds, 7, "0-9" )
  25. {
  26. }
  27.  
  28.  
  29. TInputDate::TInputDate( int x, int y )
  30.            :TInputRegExp( x, y, 7, "0-9" )
  31. {
  32. }
  33.  
  34.  
  35. Boolean TInputDate::valid( ushort command )
  36. {
  37.  switch( command )
  38.  {
  39.   case cmReleasedFocus: break;
  40.  
  41.   case cmQuit :
  42.   case cmClose:
  43.   case cmOK   :
  44.      if ( ! *data ) break;  // Allow empty entry
  45.  
  46.      unsigned long yymmdd = 0;
  47.      sscanf( data , "%lu" , &yymmdd );
  48. #pragma warn -sig
  49.      int year = yymmdd / 10000;
  50.      int month = (yymmdd % 10000) / 100;
  51.      int day = yymmdd % 100;
  52. #pragma warn .sig
  53.  
  54.      if ( ! isdatevalid(day, month, year) )
  55.         {
  56.          select();
  57.          messageBox( " \n\03Invalid date !", mfError | mfOKButton );
  58.          selectAll( True );
  59.          return False;
  60.         }
  61.      break;
  62.  }
  63.  
  64.  return TInputRegExp::valid( command );
  65. }
  66.